package com.github.shiqiyue.app.api.sapi.controller.app;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.shiqiyue.app.api.sapi.common.SApiBaseController;
import com.github.shiqiyue.app.common.enums.DeletedEnum;
import com.github.shiqiyue.app.common.req.BasePageReq;
import com.github.shiqiyue.app.common.result.BasePageResult;
import com.github.shiqiyue.app.common.result.Result;
import com.github.shiqiyue.app.common.result.SimplePageResult;
import com.github.shiqiyue.app.modules.app.entity.News;
import com.github.shiqiyue.app.modules.app.entity.Position;
import com.github.shiqiyue.app.modules.app.service.IPositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/***
 *
 * @author wenyao.wu
 */
@RestController
@RequestMapping("sapi/app/position")
public class SApiPositionController extends SApiBaseController {

    @Autowired
    private IPositionService positionService;

    @PostMapping("page")
    public Result page(BasePageReq pageReq) {
        IPage<Position> resultPage = positionService.page(pageReq);
        SimplePageResult<Position> result = new SimplePageResult();
        result.setPageInfo(resultPage);
        result.setRecords(resultPage.getRecords());
        return Result.success(result);
    }

    @PostMapping("add")
    public Result add(Position position) {
        position.setIsDeleted(DeletedEnum.NO_DEL);
        positionService.save(position);
        return Result.success();
    }

    @PostMapping("edit")
    public Result edit(Position position) {
        positionService.updateById(position);
        return Result.success();
    }

}
